package com.after.saas.mall.admin.service.impl;

import com.after.saas.common.model.dto.UserDTO;
import com.after.saas.mall.admin.model.Admin;
import com.after.saas.mall.admin.mapper.AdminMapper;
import com.after.saas.mall.admin.service.AdminService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * <p>
 * 后台用户表 服务实现类
 * </p>
 *
 * @author hjchen
 * @since 2023-03-26
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    private final AdminMapper adminMapper;

    public AdminServiceImpl(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }

    @Override
    public UserDTO loadUserByUsername(String username) {

        Admin admin = getOne(new LambdaQueryWrapper<Admin>().eq(Admin::getUsername, username));
        UserDTO userDTO=new UserDTO();
        BeanUtils.copyProperties(admin,userDTO);
        userDTO.setRoles(Arrays.asList("role_admin","role_vip"));
        return userDTO;
    }
}
